//
//  ZDMapController.m
//  ZDPension
//
//  Created by 刘甲奇 on 2017/6/22.
//  Copyright © 2017年 maker. All rights reserved.
//

#import "ZDMapController.h"
#import <MAMapKit/MAMapKit.h>
#import <AMapFoundationKit/AMapFoundationKit.h>

@interface ZDMapController ()<MAMapViewDelegate>

/**
 <#Description#>
 */
@property(nonatomic, strong) MAMapView *mapView;

@end

@implementation ZDMapController

- (void)setupUI
{
    [super setupUI];
    self.title = self.storeModel.store_name;
    
    ///初始化地图
    _mapView = [[MAMapView alloc] initWithFrame:self.view.bounds];
    _mapView.showsCompass = NO;
    _mapView.showsScale = NO;
    _mapView.delegate = self;
    _mapView.centerCoordinate = CLLocationCoordinate2DMake(self.storeModel.longs, self.storeModel.lat);
    
    ///把地图添加至view
    [self.view addSubview:_mapView];
    
}
- (void)viewDidAppear:(BOOL)animated
{
    MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc]init];
    pointAnnotation.coordinate = CLLocationCoordinate2DMake(self.storeModel.longs, self.storeModel.lat);
    pointAnnotation.title = self.storeModel.store_name;
    pointAnnotation.subtitle = self.storeModel.store_address;
    
    [_mapView addAnnotation:pointAnnotation];
}
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id <MAAnnotation>)annotation
{
    if ([annotation isKindOfClass:[MAPointAnnotation class]])
    {
        static NSString *pointReuseIndentifier = @"pointReuseIndentifier";
        MAPinAnnotationView*annotationView = (MAPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndentifier];
        if (annotationView == nil)
        {
            annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndentifier];
        }
        annotationView.canShowCallout= YES;       //设置气泡可以弹出，默认为NO
        annotationView.animatesDrop = YES;        //设置标注动画显示，默认为NO
        annotationView.draggable = YES;        //设置标注可以拖动，默认为NO
        annotationView.pinColor = MAPinAnnotationColorPurple;
        return annotationView;
    }
    return nil;
}

@end











